package com.uncheck;


import com.demo.model.*;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


public class Executor {


    /**
     * 多线程执行任务
     */
    private List<Model> executor(List<File> list) {
        ExecutorService executor = Executors.newFixedThreadPool(20);
        List<Model> collect = Collections.synchronizedList(new ArrayList<>());
        // 提交任务给线程池执行
        for (File s : list) {
            executor.submit(() -> {
                try {
                    System.out.println(s);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });
        }
        executor.shutdown();
        try {
            if (!executor.awaitTermination(3, TimeUnit.MINUTES)) {
                executor.shutdownNow();
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return collect;
    }


}
